|
|
|
|
|
|
|
vbNullString are passed. The latter case corresponds to what a DLL function expects to see for a NULL value. |
|
|
|
|
|
|
|
|
When the change is made, the function works correctly. If a valid window caption is specified, the window will be closed (try it with the Notepad application). If a valid window caption is not specified, you will see a message box, but the LastError value will be 0indicating that, even though no window was found, the function did operate correctly. |
|
|
|
|
|
|
|
|
What about an empty string? If you are running the program on Windows 95/98, an empty string is interpreted as a valid window class name. When the program fails to find a window belonging to that class, it returns 0 and sets the LastError value to 0 to indicate that no window was found. |
|
|
|
|
|
|
|
|
If you are running the program on Windows NT, an empty string is interpreted as an invalid class name, and the LastError value is set to 123 to indicate that the parameter is incorrect.2 |
|
|
|
|
|
|
|
|
Another Way to Get the LastError Description |
|
|
|
|
|
|
|
|
The FormatMessage API function is another way to obtain the string description of an error message. This function supports many different options that are beyond the scope of this discussion; all we care about is the functionality that retrieves a system message. The FormatMessage function is defined as follows: |
|
|
|
|
|
|
|
|
Private Declare Function FormatMessage Lib "kernel32" Alias _
"FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal _
dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer _
As String, ByVal nSize As Long, ByVal Arguments As Long) As Long
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 |
|
|
|
|
|
|
|
|
The dwFlags parameter is set to the constant FORMAT_MESSAGE_FROM_SYSTEM. The lpSource parameter for this mode needs to be NULL. Since the declaration is specified AsAny, be careful to pass a long parameter ByVal.3 The dwMessageId parameter is the LastError value. Set the dwLanguageId parameter to 0 to use the default system language. The lpBuffer parameter is an initialized string whose maximum length is the nSize parameter. The Arguments parameter is also NULL. |
|
|
|
 |
|
 |
|
|
2 Do Windows 95/98 and Windows NT differ in the way they handle an empty string parameter due to some underlying difference between operating systems? Probably not. Or because the NT programmer who implemented this function didn't talk to the Windows 95 programmer who implemented this function? Probably. And no. the difference is not documentedyet another example of why you should always test your programs under both Windows 95/98 and Windows NT. |
|
|
|
|
|